package mroute

import (
	"github.com/gin-gonic/gin"
	"mygo/mymongo"
	"mygo/mystruct"
	//"path/filepath"
	//"os"
	//"fmt"
	//"time"
	//"strings"
	"strconv"
	//"encoding/json"
	//"mygo/mroute/utils"
)


// 查询
func MyFastWacth(cont *gin.Context) {
	make_map := make(map[string]interface{})

	codb := mymongo.Get_Code(cont.Query("code"))
    if codb == nil {
		cont.JSON(mystruct.StatusOK, gin.H{"code": mystruct.MyCodeErr, "msg": "标识不存在"})
		return
	}
	for _, value := range codb.Body.Data {
		switch value.Select {
			case "int":
				intvalue, err := strconv.ParseInt(cont.Query(value.Value), 10, 64)
				if err == nil {
					make_map[value.Value] = intvalue
				}
			case "bool":
				bolvalue, err := strconv.ParseBool(cont.Query(value.Value))
				if err == nil {
					make_map[value.Value] = bolvalue
				}
			case "prgs":
				prsvalue, err := strconv.ParseInt(cont.Query(value.Value), 10, 64)
				if err == nil {
					make_map[value.Value] = prsvalue
				}
			default:
				make_map[value.Value] = cont.Query(value.Value)
		}
	}
	make_map["start_time"] = cont.DefaultQuery("start_time","")
	make_map["stop_time"]  = cont.DefaultQuery("stop_time","")
	make_map["_id"]  = cont.DefaultQuery("_id","")
	var limt = &mystruct.Mypage{
		Limit: mystruct.StrToInt64(cont.DefaultQuery("limit","1000")),
		Page: mystruct.StrToInt64(cont.DefaultQuery("page","0")),
	}
	ret, ret_data := mymongo.FastWacthAll(make_map, limt, codb)
	cont.JSON(mystruct.StatusOK, gin.H{"code": ret.Code, "msg": ret_data})
}

